<script language="javascript">
	function delData() {
		var obj = document.getElementsByName('txtDel[]');
		for(i = 0; i < obj.length; i++) {
			if(obj[i].checked) {
				if(document.getElementsByName('comment[]')[i].value == "") {
					document.getElementsByName('comment[]')[i].focus();
					alert('กรุณากรอกหมายเหตุค่ะ');
					return;
				}
			}
		}
		var frm = document.forms["myForm"];
		frm.action = "<?=site_url()?>StudentApprove/ignore";
		frm.submit();
	}
	function validate() {
		var obj = document.getElementsByName('txtDel[]');
		for(i = 0; i < obj.length; i++) {
			if(obj[i].checked) {
				if(document.getElementsByName('comment[]')[i].value == "") {
					document.getElementsByName('comment[]')[i].focus();
					alert('กรุณากรอกหมายเหตุค่ะ');
					return;
				}
			}
		}
		var frm = document.forms["myForm"];
		frm.action = "<?=site_url()?>StudentApprove/save";
		frm.submit();
	}
</script>
<div id="mainContent">

<form name="myForm" id="myForm" method="post" action="<?=site_url()?>StudentApprove/save" >
<table width="1000px" border="0" cellspacing="0" cellpadding="0" align="center" >
	<tr align="center">
    	<td> <h2>รายชื่อนักเรียนที่สมัครผ่านหน้าเว็บ</h2><hr/> 
    	</td>
    </tr>
	<tr style="height:10px;">
    	<td>&nbsp;</td>
    </tr>
    <tr >
    	<td><div align="center">
    	  <input name="Submit" type="button" value="ส่งประวัติเข้าฐานข้อมูลใหญ่" onclick="validate();" />
    	  <input name="Submit" type="button" value=" ลบ " onclick="delData();" />
  	  </div></td>
    </tr>
    <tr style="height:10px;">
    	<td></td>
    </tr>
	<tr>
		<td align="center">          
                  <table width="980" border="0" cellspacing="2px" cellpadding="0">
                      <tr bgcolor="#000099">
                        <td width="40px">&nbsp;</td>
                        <td width="90px"><div align="center" style="color:#FFFFFF; font-weight:bold;">วันและ<br>เวลาที่สมัคร</div></td>
                        <td width="125px"><div align="center" style="color:#FFFFFF; font-weight:bold;">ชื่อ - นามสกุล</div></td>
                        <td width="100px"><div align="center" style="color:#FFFFFF; font-weight:bold;">โรงเรียน</div></td>
                        <td width="50px"><div align="center" style="color:#FFFFFF; font-weight:bold;">ชั้น</div></td>
                        <td ><div align="center" style="color:#FFFFFF; font-weight:bold;">วิชา</div></td>
                        <td width="65px"><div align="center" style="color:#FFFFFF; font-weight:bold;">วันที่<br>เริ่มเรียน</div></td>
                        <td ><div align="center" style="color:#FFFFFF; font-weight:bold;">สถานที่เรียน</div></td>
                        <td width="85px"><div align="center" style="color:#FFFFFF; font-weight:bold;">รายละเอียด</div></td>
                        <td width="170px"><div align="center" style="color:#FFFFFF; font-weight:bold;">หมายเหตุ</div></td>
                      </tr>
                      <?php
                      $monthTh = array("","ม.ค.","ก.พ. ","มี.ค.","เม.ย.","พ.ค.","มิ.ย.","ก.ค.","ส.ค.","ก.ย.","ต.ค.","พ.ย.","ธ.ค.");
                      		$i = 1;
							foreach ($studentlList as $row) {
								echo '<tr align="left"';
								if($i % 2 == 0) {
									echo ' bgColor=#c6e2ff ';
								}
								
								echo '>';
		                        echo '<td align="center"><input type="checkbox" name="txtDel[]" value="'. $row->student_id .','.$i.'"/></td>';
		                        echo '<td align="center">' . strftime("%d",strtotime($row->create_date)) . ' ' . $monthTh[ (int) strftime("%m",strtotime($row->create_date))] .'<br>'. strftime("%H:%M",strtotime($row->create_date)). '</td>';
		                        echo '<td>' . $row->first_name . ' ' . $row->last_name . '</td>';
		                        echo '<td>' . $row->school . '</td>';
		                        echo '<td align="center">' . $row->current_class . '</td>';
		                        echo '<td align="left">';
								$i++;
		                        if($row->booking_subject01 != NULL) {
		                        	echo $row->booking_subject01;
		                        	echo ' ';
		                        }
								if($row->booking_subject02 != NULL) {
		                        	echo $row->booking_subject02;
		                        	echo ' ';
		                        }
								if($row->booking_subject03 != NULL) {
		                        	echo $row->booking_subject03;
		                        	echo ' ';
		                        }
								if($row->booking_subject04 != NULL) {
		                        	echo $row->booking_subject04;
		                        	echo ' ';
		                        }
								if($row->booking_subject05 != NULL) {
		                        	echo $row->booking_subject05;
		                        	echo ' ';
		                        }
								if($row->booking_subject06 != NULL) {
		                        	echo $row->booking_subject06;
		                        	echo ' ';
		                        }
		                        
		                        echo '&nbsp;</td>';
		                        echo '<td>' . strftime("%d",strtotime($row->study_start_date)) . ' ' . $monthTh[ (int) strftime("%m",strtotime($row->study_start_date))]. '</td>';
		                        echo '<td>'; 
		                        if($row->study_add_road == null && $row->study_add_distinct == null) 
		                        	echo $row->add_road .' '. $row->add_district.' '. $row->add_area;
		                        else 
		                        	echo $row->study_add_road .' '. $row->study_add_distinct .' '. $row->study_add_area;
		                        echo '</td>';
		                        echo '<td align="center"><div align="center"><input type="image" src="' . base_url(). 'images/detail_b.png" onmouseout="toBlack(this);" onmouseover="toColor(this);" value="'.$row->student_id . '" width="25" height="25" onclick="setID(this);"></div></td>';
		                        echo '<td align="center"><input name="comment[]" type="text" ';
		                        if(isset($row->comment)) {
		                        	echo ' value="'.$row->comment.'" ';
		                        }
		                        echo ' /></td>';
		                      	echo '</tr>';
							}
                      ?>
                  <tr style="height: 10px;">
                    <td align="right"></td>
                    <td align="left"></td>
                  </tr>
              </table>
		</td>
	</tr>
    <tr style="height:10px;">
    	<td></td>
    </tr>
</table>
<input type="hidden" name="txtId" id="txtId" />
</form>
</div>
<script type="text/javascript">
function toBlack(obj) {
	obj.src = '<?=base_url()?>images/detail_b.png';
}
function toColor(obj) {
	obj.src = '<?=base_url()?>images/detail.png';
}
function setID(obj) {
	document.getElementById('txtId').value = obj.value;
	var frm = document.forms["myForm"];
	frm.action = "<?=base_url()?>index.php/StudentInfo/detail/"+obj.value;
	frm.submit();
}
</script>